import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false
import router from './router'
import { VueAxios } from './utils/request'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import enLocale from './lan/en'
import zhLocale from './lan/zh'
import fanLocale from './lan/fan'
import VueI18n from "vue-i18n";
Vue.use(VueI18n)
const messages = {
  zh: zhLocale,
  en: enLocale,
  zh_TW: fanLocale
}
const localLang = navigator.language.split('-')[0]?.toLocaleLowerCase()
const storageLang = window.localStorage.getItem('locale')?.toLocaleLowerCase()
const l = (localLang !== 'zh' && localLang !== 'en') ? undefined : localLang
const c = (storageLang !== 'zh' && storageLang !== 'en') ? l : storageLang

localStorage.setItem('locale', c || 'zh')

const i18n = new VueI18n({
  globalInjection: true, //全局生效$t
  locale: c || 'zh',
  messages,
  legacy: false
});
Vue.use(ElementUI);
Vue.use(VueAxios)
new Vue({
  router,
  i18n,
  render: h => h(App),
}).$mount('#app')
